<template>
  <div id="noallocate" v-loading="loading">
    <v-tableTitle :btnConfig="btnConfig" @allocate="allocate"></v-tableTitle>
    <v-table :style="{ 'height': height + 'px' }" :hasEdit="false" :page="page" :pageSize="pageSize"
      :tableConfig="tableConfig" :tableData="tableData" :total="total" @findData="getTableData"
      @getTableData="getTableData" @searhData="searhData" @selectData="selectData" @upData="getTableData" ref="table">
    </v-table>
  </div>
</template>

<script>
import table from "commons/Table";
import baseMixin from "@/mixins/BaseMixin";
import tableTitle from "@/components/commons/TableTitle";

export default {
  name: "noallocate",
  mixins: [baseMixin],
  props: {
    inputData: {
      type: Object
    }
  },
  data() {
    return {
      deleteStatus: true,
      loading: false,
      tableData: [],
      pageSize: 10,
      page: 1,
      total: 10,
      tableSelectData: [],
      tableSearhData: {},
      tableConfig: [
        {
          label: this.$t('ex.wavekey'),
          prop: "wavekey",
          input: "input"
        },
        {
          label: this.$t('wave.waveStrategyName'),
          prop: "descr",
          input: "input"
        },
        {
          label: this.$t('out.wavetype'),
          prop: "wavetype",
          input: "select",
          options: this.getOptions("codelkup/RTXWAVETYPE")
        },
        {
          label: this.$t('common.status'),
          prop: "status",
          input: "select",
          options: this.getOptions("codelkup/WAVESTATUS")
        },
        {
          label: this.$t('ex.wavedate'),
          prop: "wavedate",
          input: "date",
        },
        {
          label: this.$t('wave.totalqty'),
          prop: "totalqty",
          //input: "input"
        },
        {
          label: this.$t('out.ordernumber'),
          prop: "orderline",
          //input: "input"
        },
        {
          label: this.$t('app.addName'),
          prop: "addwho",
          //input: "input"
        },
        {
          label: this.$t('out.addDate'),
          prop: "adddatestr",
          //input: "date"
        },
        {
          label: this.$t('app.editName'),
          prop: "editwho",
          //input: "input"
        },
        {
          label: this.$t('wave.modifiedon'),
          prop: "editdatestr",
          //input: "date"
        },

      ],
      height: 0
    };
  },
  computed: {
    btnConfig() {
      return [
        { label: this.$t('out.allocation'), certigier: this.deleteStatus||!this.btnPermNameList.includes('WM05020401'), invalid: "allocate" }
      ];
    }
  },
  methods: {
    allocate() {
      this.tableSelectData.map(async (item, inex) => {
        try {
          let res = await this.$api.post(`/allocateByWavekey/${item.wavekey}/${this.$store.state.wms}`, item);
          
            this.$message.success(res.returnMgr);
            let page = sessionStorage.getItem('page');
            this.getTableData(page, this.tableSearhData);
            this.$refs.table.delSelectData(item, inex);
          
        } catch (e) {
          this.$message.error(e);
        }
      })
    },
    //选中的内容
    selectData(data) {
      this.tableSelectData = data;
    },
    //搜索的值
    searhData(data, up) {
      if (!up) {
        this.tableSearhData = data;
      } else {
        this.tableSearhData = data;
        this.getTableData(1, this.tableSearhData);
      }
    },

    async getTableData(page, data) {
      this.$set(data, "curpage", page);
      try {
        this.loading = true;
        let res = await this.$api.post(`/rtxwave/queryNoAllocateList`, data);
        
          this.tableData = res.page.list;
          this.page = res.page.curpage;
          this.pageSize = res.page.pageSize;
          this.total = res.page.total;
        
      } catch (e) {
        this.$message.error(e);
      } finally {
        this.loading = false;
      }
    }
  },
  watch: {
    tableSelectData(data) {
      if (data.length > 0) {
        this.deleteStatus = false;
      } else {
        this.deleteStatus = true;
      }
    }
  },
  mounted() {
    this.getTableData(1, {});
    this.height = this.getHeight(window, 49);
  },
  components: {
    "v-table": table,
    "v-tableTitle": tableTitle
  }
};
</script>

<style scoped>
#noallocate {
  width: 100%;
  height: 99%;
}
</style>
